package com.Comprehensive.Exercise;

public class Person {
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    //定义行为：用多态来实现：
    public void keepPet(Animal animal,String something) {
        if(animal instanceof Dog d){
            System.out.println("年龄为"+ age + "岁的" + name +
                    "养了一只" + animal.getColor() + "颜色的"+ animal.getAge() + "岁的狗");
            d.eat(something);
        }else if(animal instanceof Cat c){
            System.out.println("年龄为"+ age + "岁的" + name +
                    "养了一只" + animal.getColor() + "颜色的"+ animal.getAge() + "岁的猫");
            c.eat(something);
        }
    }

}
